import Vue from 'vue'
import store from './store'
// import App from './App'
import App from './App'
// main.js
import uView from 'uview-ui'
Vue.use(uView)

// 配置请求基地址
uni.$u.http.setConfig(config => {
  config.baseURL = `https://pcapi-xiaotuxian-front-devtest.itheima.net`
  return config
})
Vue.config.productionTip = false

// 配置请求基地址
uni.$u.http.setConfig(config => {
  /* config 为默认全局配置*/
  config.baseURL = `https://pcapi-xiaotuxian-front-devtest.itheima.net` /* 根域名 */
  return config
})

uni.$u.http.interceptors.request.use(
  config => {
    // 可使用async await 做异步操作
    uni.showLoading()
    // uni.getStorage({
    //   key: 'tokenStorage',
    //   success: function (res) {
    //     console.log('获取token', res.data);
    //     // config.header.Authorization = res.data
    //     // config.header.token = res.data
    //   }
    // });
    config.header.Authorization =
      'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ7XCJuYW1lXCI6XCI0NDQyMjIyMlwiLFwiaWRcIjpcIjE1OTg1MTAwNDc5MTcyNDg1MTRcIixcInVzZXJuYW1lXCI6XCLnlKjmiLc2ODY4NjhcIn0iLCJpYXQiOjE2NzI2NjE0ODgsImV4cCI6MTY3MjkyMDY4OH0.N4ZUQQM39_fov3j1EU1GQQEE4rUISoEj7WQDLRbkbQk'
    return config
  },
  config => {
    // 可使用async await 做异步操作
    return Promise.reject(config)
  }
)
// 设置响应拦截器 关闭loading
uni.$u.http.interceptors.response.use(
  response => {
    uni.hideLoading()
    return response
  },
  response => {
    /*  对响应错误做点什么 （statusCode !== 200）*/
    console.log(response)
    return Promise.reject(response)
  }
)

App.mpType = 'app'

const app = new Vue({
  store,
  ...App
})
app.$mount()
